import HttpUtils from '../HttpUtils/HttpUtils';
// 获取当前时间戳
var timestamp = Date.parse(new Date()) / 1000;
Page({
	...HttpUtils.func,
	data: {
		showMess:true,
	},
	onUnload() {
	},
	onLoad(params) {
		this.setData({
			"msgId": params.msgId,
			"msgTitle": params.msgTitle,
			"msgContent": params.msgContent,
			"senderName": params.creator,
      "msgType": params.msgType,
			"otherId": params.otherId,
			"publishTime": this.formatDate("yyyy-MM-dd hh:mm", params.publishTime)
		});
		this.readMsg();
		if (params.msgType == 5) {
			this.loadUserMsgInfo();
		}
	},


	readMsg: function() {
		var newUrl = getApp().globalData.dangjianUrl + "/member/userMsg";
		var params = {};
    params["msgId"] = this.data.msgId + "";
		params = JSON.stringify(params);
		this.httpGet(newUrl, params, "更新消息内容已读接口加载失败").then(
			(respData) => {
				var result = respData.data.result.code;
				if (1 == result) {
					var pages = getCurrentPages();
					var prevPage = pages[pages.length - 2];
					var msgList = prevPage.data.msgList;
					for (var i in msgList) {
						if (msgList[i].msgId == this.data.msgId) {
							msgList[i].isRead = 2
							msgList[i].class = ""
						}
					}
					prevPage.loadMsg();
				} else {
          this.showPageMsg("alert", respData.data.result.description); 
				}
			}
		);
	},
	//用户通知（包括公告）消息详情接口
	loadUserMsgInfo: function() {
		var newUrl = getApp().globalData.dangjianUrl + "/member/userMsgInfo";
		var params = {};
    params["otherId"] = this.data.otherId + "";
		params["msgType"] = this.data.msgType + "";
		params = JSON.stringify(params);
		this.httpGet(newUrl, params, "用户通知（包括公告）消息详情接口操作失败").then(
			(respData) => {
				var result = respData.data.result.code;
				if (1 == result) {
					var msg = respData.data.msg; 
					this.setData({
						content: msg.content,
						icons: msg.icons,
					})
				} else {
					this.setData({
						showMess:false
					})
          this.showPageMsg("alert", respData.data.result.description); 
				}
			}
		);
	},
});
